#ifndef DECODER_XINE_H
#define DECODER_XINE_H
#include <X11/Xlib.h>
#include <X11/Xutil.h> // X11/Xlib.h must be included before X11/Xutil.h.
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/extensions/XShm.h>

#include <xine.h>
#include <xine/xineutils.h>

#include <pthread.h>

#include "Decoder.h"

/**
 * @brief The decoder using xine engine
 *
 * Decoder_xine is a wrapper class of xine engine and is implemented according
 * to the class Decoder.
 *
 */
class Decoder_xine : public Decoder{

public:
	Decoder_xine();
	~Decoder_xine();

	/* **************** */
	/* Basic Operations */
	/* **************** */
	int open(const string fileName);
	int play(const unsigned int msec);
	int pause();
	int resume();
	int stop();

	/* ******************** */
	/* Switch of fullscreen */
	/* ******************** */
	int fullscreen_sw();

	/* ********************** */
	/* Supplemental Functions */
	/* ********************** */
	const string file_filter() const;
	DECStatus getStatus() const;
	int getMediaLength() const; /* in milliseconds */
	int getCurrentPos() const;
	const string getMediaInfo() const;

	/* Return *display (for xevent handling thread)  */
	Display *getDisplay() const;

	/* Handler for expose event */
	void expose_handler( XEvent xevent );

private:
	void init();
	int init_play();

	string mediaFileName;
	bool isVideo;
	string ao_driver;
	string vo_driver;
	bool first_play;

	/* X11 related variables */
	Display *display;
	int screen;
	Window window[2];
	int fullscreen;

	/* Xevent handling thread related variable */
	pthread_t event_thread;

	/* xine related variables */
	xine_t *xine;
	xine_stream_t *stream;
	xine_video_port_t *vo_port;
	xine_audio_port_t *ao_port;
	xine_event_queue_t *event_queue;
};

#endif
